package com.tjsinfo.tjsoa.baobiao.bo;

import java.util.List;
import java.util.Map;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import com.tjsinfo.tjsoa.Dao.IHibernateDao;
import com.tjsinfo.tjsoa.Dao.IQbcDao;
import com.tjsinfo.tjsoa.baobiao.vo.THqBBYh;
import com.tjsinfo.tjsoa.Dao.ISpringDao;


/**
 * 报表用户管理
 * 
 * @author 天津市电子计算机研究所
 *
 */
	
public class THqBBYhManage implements IHqBBYhManage{
	private IQbcDao qbcDao;
	private IHibernateDao hibernateDao;
	private ISpringDao springDao;
	
	public ISpringDao getSpringDao() {
		return springDao;
	}

	public void setSpringDao(ISpringDao springDao) {
		this.springDao = springDao;
	}
	
	public IHibernateDao getHibernateDao() {
		return hibernateDao;
	}

	public void setHibernateDao(IHibernateDao hibernateDao) {
		this.hibernateDao = hibernateDao;
	}

	public IQbcDao getQbcDao() {
		return qbcDao;
	}

	public void setQbcDao(IQbcDao qbcDao) {
		this.qbcDao = qbcDao;
	}
	
	/**
	 * 取得全部用户
	 * @param
	 * @return
	 */
	public List<THqBBYh> findAll(){
		// TODO Auto-generated method stub
		DetachedCriteria criteria = DetachedCriteria.forClass(THqBBYh.class); 
		return  (List<THqBBYh>) qbcDao.getCriteria(criteria);
	}
	
	/**
	 * 取得某类报表的全部用户
	 * @param
	 * @return
	 */
	public List<THqBBYh> findAll(Integer bbid){
		// TODO Auto-generated method stub
		DetachedCriteria criteria = DetachedCriteria.forClass(THqBBYh.class); 
		criteria.add(Restrictions.eq("bbid", bbid));
		criteria.addOrder(Order.asc("sort"));
		return  (List<THqBBYh>) qbcDao.getCriteria(criteria);
	}

	/**
	 * 根据id查找
	 * @param id
	 * @return
	 */
	public THqBBYh findByid(Integer id) {
		// TODO Auto-generated method stub
		DetachedCriteria criteria = DetachedCriteria.forClass(THqBBYh.class); 
		criteria.add(Restrictions.eq("id", id));
		return  (THqBBYh) qbcDao.getCriteria(criteria).iterator().next();
	}
	
	/**
	 * 根据登录用户姓名、报表id查找报表用户
	 * @param userName
	 * @return 
	 */
	public List<THqBBYh> findbyUser(String userName, Integer bbid){
			DetachedCriteria criteria = DetachedCriteria.forClass(THqBBYh.class); 
			criteria.add(Restrictions.eq("ryxm", userName));
			criteria.add(Restrictions.eq("bbid", bbid));
			List<THqBBYh> BByhList =  qbcDao.getCriteria(criteria);
		    return  BByhList;
	}

	/**
	 * 追加用户
	 * @param user
	 */
	public void add(THqBBYh BBuser){
		// TODO Auto-generated method stub
		hibernateDao.saveObject(BBuser);
	}
	
	/**
	 * 更新用户
	 * @param BBuser
	 */
	public void update(THqBBYh BBuser) {
		// TODO Auto-generated method stub
		hibernateDao.update(BBuser);
	}
	
	/**
	 * 查找所有启用的用户
	 * @return
	 */
	public List<THqBBYh> findAllenable(Integer bbid) {
		// TODO Auto-generated method stub
		DetachedCriteria criteria = DetachedCriteria.forClass(THqBBYh.class); 
		criteria.add(Restrictions.eq("bbid",bbid));
		criteria.add(Restrictions.eq("state", "1"));
		return  (List<THqBBYh>) qbcDao.getCriteria(criteria);
	}


}


